﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.LIB.YJKControls;

namespace ElectricDim
{
	public partial class DlgWireLoopDim : DlgModelLess
	{
		public static DlgWireLoopDim GetInstance(UIApplication app, WindowHandle handel)
		{
			if (DlgWireLoopDim.dll == null || DlgWireLoopDim.dll.IsDisposed)
			{
				DlgWireLoopDim.dll = new DlgWireLoopDim(app, handel);
			}
			return DlgWireLoopDim.dll;
		}

		public ElementType GetElementType()
		{
			Family labelFamily = ElectricMark.WireLoopMark(this.mApp.ActiveUIDocument.Document)[0].LoadInSubTrans(this.mApp.ActiveUIDocument.Document);
			return ElectricalUtils.GetLeaderType(this.mApp.ActiveUIDocument.Document, this.GetDimLinkStyle(), labelFamily);
		}

		public LabelType GetLabelType()
		{
			if (this.rbFromWire.Checked)
			{
				return LabelType.FromObject;
			}
			return LabelType.FromText;
		}

		public string Label
		{
			get
			{
				return this.txtInput.Text;
			}
		}

		public LeaderStyle GetDimStyle()
		{
			if (this.rbNullLeader.Checked)
			{
				return LeaderStyle.None;
			}
			if (this.rbHasLeader.Checked)
			{
				return LeaderStyle.HasLeader;
			}
			return LeaderStyle.Orthogonal;
		}

		public PointStyle GetDimLinkStyle()
		{
			if (this.rbNull.Checked)
			{
				return PointStyle.None;
			}
			return PointStyle.Line;
		}

		public DlgWireLoopDim(UIApplication app, WindowHandle handle) : base(handle)
		{
			this.mApp = app;
			this.InitializeComponent();
		}

		private void rbNullLeader_CheckedChanged(object sender, EventArgs e)
		{
			this.groupBox3.Enabled = !this.rbNullLeader.Checked;
		}

		private void rbFromWire_CheckedChanged(object sender, EventArgs e)
		{
			this.txtInput.Enabled = !this.rbFromWire.Checked;
		}

		private static DlgWireLoopDim dll;

		private UIApplication mApp;
	}
}
